#include <cstdio>
#include <algorithm>

struct Student {
    char name[15];
    int score[4];
};
Student stu[50];

bool cmp(Student x, Student y) {
    int sumx = x.score[0] + x.score[1] + x.score[2] + x.score[3];
    int sumy = y.score[0] + y.score[1] + y.score[2] + y.score[3];

    return sumx > sumy;
}

int main()
{
    int N;
    scanf("%d", &N);
    for(int i = 0; i < N; i++) {
        scanf("%s", stu[i].name);
        for(int j = 0; j < 4; j++) {
            scanf("%d", &stu[i].score[j]);
        }
    }

    std::sort(stu, stu+N, cmp);
    for(int i = 0; i < 3; i++) {
        printf("%s\n", stu[i].name);
    }

    return 0;
}